﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Criterion;
using RevClinic.Core.Domain;

namespace RevClinic.Core.Services
{
    public class UserService : IUserService
    {
        private ISession _session;

        public UserService(ISessionFactory sessionFactory)
        {
            _session = sessionFactory.GetCurrentSession();
        }

        public bool IsUserLoginOccupied(string login)
        {
            int count = _session
                .CreateQuery("select count(*) from User u where u.Login=:login")
                .SetParameter("login", login)
                .UniqueResult<int>();
            return count == 0;
        }
    }
}
